// Learn cc.Class:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        m_pages:{
            default:[],
            type:cc.Node,
        },
        levelPrefab:cc.Prefab,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {

    },

    start () {
        this.initAllLevel();
        var levelsData = {};
        levelsData[0] = {}
        levelsData[0].rows = 4,
        levelsData[0].cols = 4,
        levelsData[0].grid = [
                [1, 1, 1, 1],
                [1, 1, 0, 1],
                [1, 0, 0, 0],
                [1, 1, 0, 1]
            ]
        
console.log(levelsData[0].cols);
    },

    update (dt) {

    },
    //更新关卡
    updateLevelIcon:function(level){
        this.allLevelIcon[level].getComponent('levelIcon').initLevelLock(false);
    },
    //初始化关卡
    initAllLevel:function(){
        this.allLevelIcon = [];
        //1-20
        for (let i = 0; i < 100; i++) {
            var pageIndex = Math.floor(i/20);
            var pageNum = i%20;
            var col = pageNum%4;
            var row = Math.floor(pageNum/4);
            var levelIcon = cc.instantiate(this.levelPrefab);
            levelIcon.position = cc.v2(-225+150*col,350-175*row)//450-112
            levelIcon.parent = this.m_pages[pageIndex];
            levelIcon.getComponent('levelIcon').initLevelNum(i+1);
            levelIcon.getComponent('levelIcon').initLevelLock(false);
            this.allLevelIcon.push(levelIcon);
        }
        /*
        //21-40
        for (let i = 0; i < 20; i++) {
            var col = i%4;
            var row = Math.floor(i/4);
            var levelIcon = cc.instantiate(this.levelPrefab);
            levelIcon.position = cc.v2(-225+150*col,450-450/4-225*row)//450-112
            levelIcon.parent = this.m_pages[1];
            levelIcon.getComponent('levelIcon').initLevelNum(i+20);
            levelIcon.getComponent('levelIcon').initLevelLock(true);
            this.allLevelIcon.push(levelIcon);
        }
        //41-60
        for (let i = 0; i < 20; i++) {
            var col = i%4;
            var row = Math.floor(i/4);
            var levelIcon = cc.instantiate(this.levelPrefab);
            levelIcon.position = cc.v2(-225+150*col,450-450/4-225*row)//450-112
            levelIcon.parent = this.m_pages[2];
            levelIcon.getComponent('levelIcon').initLevelNum(i+40);
            levelIcon.getComponent('levelIcon').initLevelLock(true);
            this.allLevelIcon.push(levelIcon);
        }
        //61-80
        for (let i = 0; i < 20; i++) {
            var col = i%4;
            var row = Math.floor(i/4);
            var levelIcon = cc.instantiate(this.levelPrefab);
            levelIcon.position = cc.v2(-225+150*col,450-450/4-225*row)//450-112
            levelIcon.parent = this.m_pages[3];
            levelIcon.getComponent('levelIcon').initLevelNum(i+60);
            levelIcon.getComponent('levelIcon').initLevelLock(true);
            this.allLevelIcon.push(levelIcon);
        }
        //81-100
        for (let i = 0; i < 20; i++) {
            var col = i%4;
            var row = Math.floor(i/4);
            var levelIcon = cc.instantiate(this.levelPrefab);
            levelIcon.position = cc.v2(-225+150*col,450-450/4-225*row)//450-112
            levelIcon.parent = this.m_pages[4];
            levelIcon.getComponent('levelIcon').initLevelNum(i+80);
            levelIcon.getComponent('levelIcon').initLevelLock(true);
            this.allLevelIcon.push(levelIcon);
        }
        */
    },
});
